package com.soulgame;

import com.soul.sdk.utils.json.KJSONObject;
import com.soulgame.sgsdkproject.sgtool.AmountUtils;

/**
 * @author lch
 * @version Create time：2017-3-24
 * @类说明：支付所需参数封装类
 */
public class VoPayParam {

	private KJSONObject mPayDataJSON;

	public VoPayParam(KJSONObject pSdkParamesJSON) {
		if (pSdkParamesJSON != null) {
			this.mPayDataJSON = pSdkParamesJSON.getJSONObject("payData");
		}

	}

	/**
	 * 获取计费点，缺省返回 0
	 * 
	 * @param pProductId
	 * @return
	 */
	public String getPayCode(String pProductId) {
		String aPayCode = "0";
		if (mPayDataJSON != null) {
			KJSONObject productDataJSON = mPayDataJSON.getJSONObject(pProductId);
			if (productDataJSON != null) {
				KJSONObject baiduDataJSON = productDataJSON.getJSONObject("baidu");
				if (baiduDataJSON != null) {
					aPayCode = baiduDataJSON.getString("paycode", "0");
				}
			}
		}
		return aPayCode;
	}

	/**
	 * 商品名称
	 * @param pProductId
	 * @return
	 */
	public String getPayProductName(String pProductId) {
		String aName = "";
		if (mPayDataJSON != null) {
			KJSONObject productDataJSON = mPayDataJSON.getJSONObject(pProductId);
			if (productDataJSON != null) {
				aName = productDataJSON.getString("name", "");
			}
		}
		return aName;
	}

	/**
	 * 获取价格，并转换为元
	 * 
	 * @param pProductId
	 * @return
	 */
	public String getPayPrice(String pProductId) {
		String aPrice = "0";
		if (mPayDataJSON != null) {
			KJSONObject productDataJSON = mPayDataJSON.getJSONObject(pProductId);
			if (productDataJSON != null) {
				String fPrice = productDataJSON.getString("price", "0");
				// 分转为元
				aPrice = AmountUtils.changeF2Y(fPrice);
			}
		}
		return aPrice;
	}

}
